﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using IDAL;
using Model;

namespace DAL
{
    public class TTestItem : BaseRepository<TTestItemInfo>, ITTestItem
    {
        private const string PARM_TESTITEM_PRODUCTSN = "@ProductSN";
        private const string PARM_TESTITEM_TESTTIME = "@RecordTime";

        public IList<TTestItemInfo> LoadEntities()
        {
            return null;
        }

        public TTestItemInfo LoadEntity<T1>(T1 Id)
        {
            return null;
        }

        public IList<TTestItemInfo> GetTestItems(string productSN, DateTime testTime)
        {
            //Create a parameter    
            SqlParameter[] testItemParms = GetSNTParameters();
            //Bind the parameter
            testItemParms[0].Value = productSN;
            testItemParms[1].Value = testTime;
            return ExcuteSqlToGetEntities("TTestItem_select_SNDT", testItemParms);
        }

        #region 参数部分
        private static SqlParameter[] GetSNTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_TESTITEM_PRODUCTSN, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_TESTITEM_TESTTIME, SqlDbType.DateTime, 8)                
                };
            return parms;
        }
        #endregion

        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override TTestItemInfo GetEntityRecord(SqlDataReader rdr)
        {
            TTestItemInfo pro = new TTestItemInfo
            {
                ProductSN = rdr.GetValue(0).ToString(),
                RecordTime = rdr.GetDateTime(1),
                TestItemName = rdr.GetValue(2).ToString(),
                TestTypeName = rdr.GetValue(3).ToString(),
                TestTypeID = rdr.GetInt32(4),
                StartF = rdr.GetDecimal(5),
                StopF = rdr.GetDecimal(6),
                Max = rdr.GetDecimal(7),
                Min = rdr.GetDecimal(8),
                HighSpec = rdr.GetDecimal(9),
                LowSpec = rdr.GetDecimal(10),
                IsPass = rdr.GetValue(11).ToString()
            };
            return pro;
        }
        #endregion
    }
}
